package com.zqxq.lottery.controller.sys;

import com.baomidou.mybatisplus.plugins.Page;
import com.zqxq.common.constant.Result;
import com.zqxq.common.enums.CodeEnum;
import com.zqxq.lottery.entity.vo.jczq.JczqMatchLiveVO;
import com.zqxq.lottery.entity.vo.sys.SysMatchVO;
import com.zqxq.lottery.service.jczq.IJczqMatchResultService;
import com.zqxq.lottery.service.jczq.IMatchManagementService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 苦智
 * @date 2018/5/7 12:01
 * @description 赛事管理
 * @ClassName MatchManagementController
 */
@RestController
@Slf4j
public class MatchManagementController extends SysBaseController{

    @Autowired
    private IMatchManagementService matchManagementService;
    @Autowired
    private IJczqMatchResultService jczqMatchResultService;

    /**
    * @Author 苦智
    * @Description 获取赛事管理联赛列表、近3日已设热门赛事场次
    * @Date 11:35 2018/9/26
    * @Param []
    * @return com.zqxq.common.constant.Result
    **/
    @PostMapping("/match/leagueList")
    public Result getAllLeague(){
        Map<String,Object> map = new HashMap();
        List<Map<String,Object>> leagueList = matchManagementService.getAllLeague();
        int manualCount = matchManagementService.getManualCount();
        map.put("leagueList",leagueList);
        map.put("manualCount",manualCount);
        return new Result(CodeEnum.SUCCESS.getCode(),CodeEnum.SUCCESS.getMsg(),map);
    }

    /**
    * @Author 苦智
    * @Description 根据联赛id查找未开始赛事
    * @Date 11:37 2018/9/26
    * @Param [leagueId]
    * @return com.zqxq.common.constant.Result
    **/
    @PostMapping("/match/matchList")
    public Result selectMatchList(Long leagueId,Integer isHot,String matchTime,String league){
        List<SysMatchVO> resultList = matchManagementService.selectMatchList(leagueId,isHot,matchTime,league);
        return new Result(CodeEnum.SUCCESS.getCode(),CodeEnum.SUCCESS.getMsg(),resultList);
    }

    @PostMapping("/match/edit")
    public Result updateMatchHotStatus(Long id,Integer isHot){
        matchManagementService.updateMatchHotStatus(id,isHot);
        return new Result(CodeEnum.SUCCESS.getCode(),"赛事修改成功");
    }

    @PostMapping("/match/matchResultList")
    public Result selectMatchResultList(Integer pageNo,Integer pageSize,Long id,Long leagueId,Integer status,String matchTime,String league){
        Map<String,Object> map = matchManagementService.selectMatchResultList(pageNo,pageSize,id,leagueId,status,matchTime,league);
        return new Result(CodeEnum.SUCCESS.getCode(),CodeEnum.SUCCESS.getMsg(),map);
    }

    @PostMapping("/match/saveMatchResult")
    public Result saveMatchResult(@RequestBody JczqMatchLiveVO vo){
        Result rs = new Result();
        try{
            JczqMatchLiveVO jczqMatchLiveVO = jczqMatchResultService.saveMatchResult(vo);
            rs.setData(jczqMatchLiveVO);
        }catch(Exception e){
            rs.setCode(CodeEnum.FAIL.getCode());
            rs.setMsg(CodeEnum.FAIL.getMsg());
            log.error("MatchResult Save  Error:",e);
        }
        return rs;
    }
}
